/*
 * @Author: xushuhao
 * @Email: xshmouse@163.com
 * @Date: 2020-04-15 15:51:40
 * @Last Modified by: xushuhao
 * @Last Modified time: 2020-04-30 09:49:13
 * @Description: 初始化App入口逻辑
 */

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_code_framework/providers/demo_model.dart';
import 'package:flutter_code_framework/route/routes.dart';
import 'package:flutter_code_framework/utils/global.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
// import 'package:shared_preferences/shared_preferences.dart';
import 'package:provider/provider.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter/rendering.dart';
final Router router = Router();
ThemeData appTheme;
const debug = false;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  //SharedPreferences prefs = await SharedPreferences.getInstance();
  await FlutterDownloader.initialize(debug: debug);
  //一直保持黑色状态栏
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
debugPaintSizeEnabled = !true;
  runApp(
    MultiProvider(
      providers: [
        // 此处维护全局Provier值 demo_page.dart 里有demo
        ChangeNotifierProvider.value(value: DemoModel()),
      ],
      child: MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  MyApp({Key key}) : super(key: key);

  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: G.navigatorKey,
      showPerformanceOverlay: false,
      theme: G.brigtTheme,
      darkTheme: G.darkTheme,
      title: 'FrameWork Pege',
      initialRoute: '/startup_page',
      onGenerateRoute: router.getRoutes,
      debugShowCheckedModeBanner: false,
      localizationsDelegates: [
        GlobalCupertinoLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [const Locale("zh", "CH"), const Locale("en", "US")],
    );
  }
}
